//
//  yueShaoDetailViewController.m
//  YuErmuYing
//
//  Created by Tiancheng on 16/8/16.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "yueShaoDetailViewController.h"
#import "HttpRequest.h"
#import "yueSao01.h"
#import "yueShaoViewController.h"
#import "yueSaoDetail.h"
#import "UIImageView+WebCache.h"
#import "yueShaoOrderViewController.h"
//通过判断来确定出跳转到哪个界面
#import "tiaoZhuanView.h"
#import "SVProgressHUD.h"
#import "Macros.h"

@interface yueShaoDetailViewController ()
@property (weak, nonatomic) IBOutlet UIView *backGroundView;

@property (weak, nonatomic) IBOutlet UIView *headerView;
//头像照片
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
//头像名字
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
//第一个星星图片
@property (weak, nonatomic) IBOutlet UIImageView *StarImageView01;
//第二个星星图片
@property (weak, nonatomic) IBOutlet UIImageView *StarImageView02;
//第三个星星图片
@property (weak, nonatomic) IBOutlet UIImageView *StarImageView03;
//第四个星星图片
@property (weak, nonatomic) IBOutlet UIImageView *StarImageView04;
@property (weak, nonatomic) IBOutlet UIButton *appointmentBtn;

//经验多少年
@property (weak, nonatomic) IBOutlet UILabel *experienceNumber;
//擅长做的事
@property (weak, nonatomic) IBOutlet UILabel *beGoodAtLabel;
//原来的价格
@property (weak, nonatomic) IBOutlet UILabel *originalPrice;
//现在的价格
@property (weak, nonatomic) IBOutlet UILabel *nowPrice;
//个人介绍的内容
@property (weak, nonatomic) IBOutlet UILabel *introudceLabel;
//网络数据的数组
@property(nonatomic,copy)NSMutableArray*json_Array1;
//把星星装到数组里
@property(nonatomic,copy)NSMutableArray *starArray;
//更改网络地址(确定是催乳师接口,还是月嫂接口)
@property(nonatomic,copy)NSString *urlString;
@property(nonatomic,copy)NSMutableDictionary *params;
//判断是催乳师还是月嫂进行更改字体
@property (weak, nonatomic) IBOutlet UILabel *changeTitle;

@property(nonatomic,retain)UIView *backView;
@end

@implementation yueShaoDetailViewController
@synthesize json_Array1,starArray,urlString,params;
-(void)viewDidAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=YES;
    self.tabBarController.tabBar.hidden=NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
//    NSLog(@"121212");
//    starArray=[NSMutableArray array];
    //背景色为灰色
    self.backGroundView.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    //粉色
    self.headerView.backgroundColor=[UIColor colorWithRed:244/255.0 green:142/255. blue:177/255.0 alpha:1];
//设置粉色按钮
    self.appointmentBtn.backgroundColor=[UIColor colorWithRed:244/255.0 green:142/255. blue:177/255.0 alpha:1];
    //     更改确定按钮的边框
        self.appointmentBtn.clipsToBounds=YES;
        self.appointmentBtn.layer.cornerRadius=3.0f;
    //把改头像形状更改为圆形
//    userIconImageV.layer.masksToBounds=YES;
//    userIconImageV.layer.cornerRadius=188/2.0f
    self.headerImageView.clipsToBounds=YES;
    self.headerImageView.layer.cornerRadius=self.headerImageView.frame.size.width/2;
    //从网路里获取数组
    [self updateDataFromNet];
    [SVProgressHUD showWithStatus:@"加载中请稍后..."];
    self.backView=[[UIView alloc]initWithFrame:CGRectMake(0, 20, screenWidth, screenHeight-20)];
    self.backView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.backView];
    
}
-(void)updateDataFromNet
{
    yueSao01 *ys01=[yueSao01 sharedManager];
    //网络请求
    NSString *str=ys01.idString;
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    if (tzv.yueShao==1)
    {
        //月嫂
        self.changeTitle.text=@"擅长";
        urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/position/detailbs"];
        params = [NSMutableDictionary dictionary];
        params[@"position_id"] = str;
        
    }else{
        //催乳师
        self.changeTitle.text=@"优惠";
        urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/position/detailpl"];
        params = [NSMutableDictionary dictionary];
//        NSLog(@"strstr=%@",str);
        params[@"position_id"] = str;
    }

    
//    urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/admin/position/detailbs"];
//        NSMutableDictionary *params = [NSMutableDictionary dictionary];
//        params[@"position_id"] = str;
//    yueSaoDetail *ysd=[yueSaoDetail shardeManager];
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:params success:^(id responseObject)
     {
         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         json_Array1=[json objectForKey:@"data"];
         if (json_Array1.count>0)
         {
             [self dismiss];
//             //人名
//             ysd.name=[json_Array1[0] objectForKey:@"position_name"];
//             //星星数量
//             ysd.starNumbers=[json_Array1[0] objectForKey:@"position_star"];
//             //头像
//             ysd.pic=[json_Array1[0] objectForKey:@"position_pic"];
////             NSLog(@"picpicpicpic=%@",ysd.pic);
//             //经验
//             ysd.experienceAge=[json_Array1[0] objectForKey:@"position_work_age"];
//             if (tzv.yueShao==1)
//             {
//                 //月嫂
//              ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_good"];
//             }else{
//                 //催乳师
//             ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_benefit"];
//             ysd.type=[json_Array1[0] objectForKey:@"position_type"];
//                 NSLog(@"ysd.type=%@",ysd.type);
//             }             //擅长
////             ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_good"];
//             //原价
//             ysd.originalPrice=[json_Array1[0] objectForKey:@"position_purchase"];
//             //现价
//             ysd.nowPrice=[json_Array1[0] objectForKey:@"position_currentprice"];
//             //个人评价
//             ysd.introduce=[json_Array1[0] objectForKey:@"position_describle"];
//             self.nameLabel.text=ysd.name;
//             self.experienceNumber.text=ysd.experienceAge;
//             self.beGoodAtLabel.text=ysd.beGoodAt;
//             self.originalPrice.text=ysd.originalPrice;
//             self.nowPrice.text=ysd.nowPrice;
//             self.introudceLabel.text=ysd.introduce;
//             
//             [self changeStarPicture:ysd.starNumbers];
         }
//         NSURL* imagePath = [NSURL URLWithString:ysd.pic];
//         //给一张默认图片，先使用默认图片，当图片加载完成后再替换
//         [self.headerImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];

       //  NSLog(@"json=%@",json);
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];    
}
- (void)dismiss
{
    [self.backView removeFromSuperview];
    [SVProgressHUD dismiss];
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    yueSaoDetail *ysd=[yueSaoDetail shardeManager];
    //人名
    ysd.name=[json_Array1[0] objectForKey:@"position_name"];
    //星星数量
    ysd.starNumbers=[json_Array1[0] objectForKey:@"position_star"];
    //头像
    ysd.pic=[json_Array1[0] objectForKey:@"position_pic"];
    //             NSLog(@"picpicpicpic=%@",ysd.pic);
    //经验
    ysd.experienceAge=[json_Array1[0] objectForKey:@"position_work_age"];
    if (tzv.yueShao==1)
    {
        //月嫂
        ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_good"];
    }else{
        //催乳师
        ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_benefit"];
        ysd.type=[json_Array1[0] objectForKey:@"position_type"];
        NSLog(@"ysd.type=%@",ysd.type);
    }             //擅长
    //             ysd.beGoodAt=[json_Array1[0] objectForKey:@"position_good"];
    //原价
    ysd.originalPrice=[json_Array1[0] objectForKey:@"position_purchase"];
    //现价
    ysd.nowPrice=[json_Array1[0] objectForKey:@"position_currentprice"];
    //个人评价
    ysd.introduce=[json_Array1[0] objectForKey:@"position_describle"];
    self.nameLabel.text=ysd.name;
    self.experienceNumber.text=ysd.experienceAge;
    self.beGoodAtLabel.text=ysd.beGoodAt;
    self.originalPrice.text=ysd.originalPrice;
    self.nowPrice.text=ysd.nowPrice;
    self.introudceLabel.text=ysd.introduce;
    [self changeStarPicture:ysd.starNumbers];
    NSURL* imagePath = [NSURL URLWithString:ysd.pic];
    //给一张默认图片，先使用默认图片，当图片加载完成后再替换
    [self.headerImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
}
//更改星星的图片
-(void)changeStarPicture:(NSString *)number
{
    int num=[number intValue];
    starArray =[NSMutableArray arrayWithObjects:self.StarImageView01,self.StarImageView02,self.StarImageView03,self.StarImageView04, nil];
    if (num>4)
    {
        num=4;
    }
    for (int i=0;i<num; i++)
    {
        UIImageView *imageView00=starArray[i];
        imageView00.image=[UIImage imageNamed:@"star-click"];
    }

}
//预定月嫂的方法
- (IBAction)appointment:(id)sender
{
    //跳转到月嫂订单界面
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    tzv.yueShaoViewNumber=2;
    yueShaoOrderViewController *ysovc=[yueShaoOrderViewController new];
    [self.navigationController pushViewController:ysovc animated:YES];
}

- (IBAction)goBack:(id)sender
{
    yueShaoViewController *ysc=self.navigationController.viewControllers[1];
    [self.navigationController popToViewController:ysc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
